package com.semidata.trp.decision.business;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.semidata.trp.message.business.Business;

public class Position {

	private int id;
	private int width;
	private int height;
	private int size;
	private int min;
	private int max;
	private Set<Material.Type> types;
	private int mediaType;
	private List<Resource> resources;

	public String toString() {
		StringBuffer sb = new StringBuffer();

		sb.append("Position ").append(id);
		sb.append(" [").append(width).append(", ").append(height).append(", ")
				.append(size).append(", ").append(min).append(", ").append(max)
				.append(", ").append(mediaType).append(", [");
		for (Material.Type type : types) {
			sb.append(type).append(", ");
		}
		sb.append("]]\n");

		for (Resource resource : resources) {
			sb.append(resource.toString());
		}
		sb.append('\n');
		return sb.toString();
	}

	public Position(Business.Position data) {
		try {
			this.id = data.getId();
			this.width = data.getWidth();
			this.height = data.getHeight();
			this.size = data.getSize();
			this.min = data.getMin();
			this.max = data.getMax();
			this.mediaType = data.getMediaType();
			this.types = new HashSet<>();

			for (String type : data.getTypeList()) {
				types.add(Material.Type.valueOf(type));
			}
			resources = new ArrayList<>();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public int getId() {
		return id;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public int getSize() {
		return size;
	}

	public int getMin() {
		return min;
	}

	public int getMax() {
		return max;
	}

	public Set<Material.Type> getTypes() {
		return types;
	}

	public void addResource(Resource resource) {

		resources.add(resource);
	}

	public List<Resource> getResources() {
		return resources;
	}

	public int getMediaType() {
		return mediaType;
	}

	public void setMediaType(int mediaType) {
		this.mediaType = mediaType;
	}
}
